package filter;

import java.util.BitSet;
import java.util.Date;

class HashFunctions {
    private int capacity;
    private int seed;

    public HashFunctions(int capacity, int seed){
        this.capacity = capacity;
        this.seed = seed;
    }

    public int hash(String key){
        int res = 1;
        int h = key.hashCode();
        res += h ^ (h >>> 16) * seed;
        return (capacity-1) & res;
    }
}

public class MyBloomFilter {
    private static final int DEFAULT_SIZE = 1 << 10;
    private static final int[] seeds = {51, 72, 18, 46, 32, 24};

    private BitSet bitSet;
    private HashFunctions[] hashFunctions;

    public MyBloomFilter(){
        bitSet = new BitSet(DEFAULT_SIZE);
        hashFunctions = new HashFunctions[seeds.length];
        for (int i = 0; i < seeds.length; i++) {
            hashFunctions[i] = new HashFunctions(DEFAULT_SIZE, seeds[i]);
        }
    }

    public void set(String value){
        if(value == null){
            return;
        }
        for(HashFunctions tmp : hashFunctions){
            bitSet.set(tmp.hash(value));
        }
    }

    public boolean contains(String value){
        if(value == null){
            return false;
        }
        for (HashFunctions tmp : hashFunctions){
            if(!bitSet.get(tmp.hash(value))){
                return false;
            }
        }
        return true;
    }
}
